package com.goods.link.controller;

import com.goods.link.LinkProcess;
import com.goods.link.LinkProduct;
import com.goods.link.bean.ExProduct;
import com.goods.link.amazon.RequestAndExtractor;
import com.goods.link.bean.ProductPrice;
import com.goods.link.bean.ResultExProduct;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created by zhengjunbo on 2015/9/16.
 */

@Controller
public class LinkController {

    @Autowired
    private  RequestAndExtractor requestAndExtractor;

    @Autowired
    private LinkProcess linkProcess;

    @RequestMapping("/product")
    @ResponseBody
    public ResultExProduct getProduct(String url){
        ResultExProduct product = requestAndExtractor.getProduct(url);
        return product;
    }

    @RequestMapping("/price")
    @ResponseBody
    public ProductPrice getProductPrice(String site,String url){
        System.out.println("site:"+site);
        System.out.println("url:"+url);
        ProductPrice productPrice = new ProductPrice();
        try {
            LinkProduct product = linkProcess.findProduct(site, url);
            productPrice.setLinkProduct(product);
            productPrice.setStatus("1");
        } catch (Exception e) {
            productPrice.setStatus("0");
            e.printStackTrace();
        }
        return productPrice;
    }







}
